import dayjs from 'dayjs'
import { create } from 'zustand'

export type TabItem = {
  label: string | React.ReactNode
  key: string
  index: number
  isOther: boolean
}

export const MonthYearTabs = [
  {
    label: '月累计',
    value: '2',
  },
  {
    label: '年累计',
    value: '1',
  },
] as const

export type MonthYearKey = typeof MonthYearTabs[number]['value']

export type ServiceTypeItem = {
  label: string
  value: string
}

export type SaleTabStore = {
  active: TabItem | null
  setActive(t: TabItem): void
  serviceType: ServiceTypeItem
  setServiceType(type: ServiceTypeItem): void
  currentDate: number
  setCurrentDate(v: number): void
  monthOrYear: MonthYearKey
  setMonthOrYear(v: MonthYearKey): void
}

export const useSaleTabStore = create<SaleTabStore>((set) => {
  return {
    active: { label: "传统航线业务", key: "1", index: 0, isOther: false },
    serviceType: "",
    currentDate: dayjs().subtract(1, "day"),
    setActive(tab: TabItem) {
      set({
        active: tab,
      });
    },
    setServiceType(typeItem: ServiceTypeItem) {
      set({
        serviceType: typeItem,
      });
    },
    setCurrentDate(val: number) {
      set({
        currentDate: val,
      });
    },
    monthOrYear: MonthYearTabs[0].value,
    setMonthOrYear(k: MonthYearKey) {
      set({
        monthOrYear: k,
      });
    },
  };
})
